/*
 * @lc app=leetcode.cn id=225 lang=cpp
 *
 * [225] 用队列实现栈
 */

// @lc code=start
class MyStack {
private:
    //只是备份, 并不像栈那样, 会改变元素先后关系
    std::queue<int> Que1;
    std::queue<int> Que2;   //备份

public:
    MyStack() {

    }
    
    void push(int x) {
        Que1.push(x);
    }
    
    int pop() {
        int result;
        while (Que1.size() > 1) {
            Que2.push(Que1.front());
            Que1.pop();
        }

        result = Que1.front();

        Que1 = std::move(Que2);
        return result;
    }
    
    int top() {
        return Que1.back();
    }
    
    bool empty() {
        return Que1.size() == 0;
    }
};

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack* obj = new MyStack();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->top();
 * bool param_4 = obj->empty();
 */
// @lc code=end

